<%@ page import="com.useeinfo.oa.modules.security.enums.OperationRoleEnum" %>
<%@ page import="com.useeinfo.oa.modules.security.util.SessionKeyUtils" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<div class="main-content">
    <div class="box box-main">
        <form id="inputForm" model="post" action="<c:url value="/web/admin/systemRole/executeUserRoleBatch.action"/>"
              method="post" class="form-horizontal">
            <div class="box-body">
                <div class="form-unit">批量调整角色</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> 部门：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="select_organization" name="select_organization"
                                       class="form-control required "/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> 岗位：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="select_position" name="select_position" class="form-control required "/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 角色：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="select_role" name="select_role" class="form-control required "/>
                            </div>
                        </div>
                    </div>
                    <%if (OperationRoleEnum.admin.getCode().equals(SessionKeyUtils.getSessionUser(request).getOperationRole())) { %>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> 选择企业：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="select_enterprise" id="select_enterprise" name="select_enterprise"
                                       class="form-control required">
                            </div>
                        </div>
                    </div>
                    <%} else {%>
                    <input type="hidden" name="select_enterprise[]"
                           value="<%=SessionKeyUtils.getSessionEnterprise(request).getId() %>">
                    <%}%>
                </div>
            </div>

            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i>
                            保 存
                        </button>&nbsp;

                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="closeView()"><i
                                class="fa fa-times"></i> 关 闭
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    $("#inputForm").validate({
        submitHandler: function (form) {
            js.ajaxSubmitForm($(form), function (data) {
                js.showMessage(data.msg, '', data.status == Global.NO ? 'success' : 'error');
                if (data.status == Global.NO) {
                    closeView();
                    $('#dataGrid').dataGrid("refresh");
                }
            }, "json");
        }
    });

    function closeView() {
        layer.close(LayWin['wChangeRole']);
    }

    //部门
    var select_organization = $('#select_organization').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/organization/getOrganizationListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '选择部门',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('')
    });

    //岗位
    var select_position = $('#select_position').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/position/getPositionListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '选择岗位',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('')
    });
    $(select_position).on('beforeload', function (e, m) {
        if (select_organization.getValue() == "") {
            js.showMessage("请选择部门！");
        } else {
            select_position.setDataUrlParams({"organizationId": select_organization.getValue() + ""});
        }
    });

    //角色
    var select_role = $('#select_role').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/systemRole/getSystemRoleListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '选择角色',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('')
    });

    <%if (OperationRoleEnum.admin.getCode().equals(SessionKeyUtils.getSessionUser(request).getOperationRole())) { %>
    var select_enterprise = $('#select_enterprise').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/enterprise/getEnterpriseListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('')
    });
    <%} %>

</script>


